package com.runda.partypolicy.app.di.modules;

import android.app.Application;


import com.blankj.utilcode.util.CacheDiskUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.runda.partypolicy.app.others.Constants;
import com.runda.partypolicy.app.others.Rxjava.RxEventManager;
import com.runda.partypolicy.app.repository.api.APIServiceCreator;
import com.runda.partypolicy.app.repository.db.LocalDB;


import java.io.File;

import javax.inject.Singleton;

import androidx.room.Room;
import dagger.Module;
import dagger.Provides;

/**
 * author:   robin_zzw
 * date:    2018/1/10
 * version: v1.0
 * description: 整体Module
 */
@Module
public class AppModule {

    @Provides
    @Singleton
    Gson provideGson() {
        return new GsonBuilder().create();
    }

    @Provides
    @Singleton
    LocalDB provideLocalDB(Application app) {
        return Room.databaseBuilder(app, LocalDB.class, "PartyPolicy.db")
                .allowMainThreadQueries().build();
    }

    @Provides
    @Singleton
    APIServiceCreator provideAPIServiceCreator() {
        return new APIServiceCreator();
    }

    @Provides
    @Singleton
    CacheDiskUtils provideCacheUtils() {
        return CacheDiskUtils.getInstance(new File(Constants.PATH_CACHE));
    }

    @Provides
    RxEventManager provideRxEventManager() {
        return new RxEventManager();
    }
}
